package org.glutenberg;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Style;

public class Error extends Form implements ActionListener {
	
	private Command exit;
	private Command aboutCommand;
	private TextArea error;
	private Handbook hb;

	public Error(Handbook hb){
		this.hb = hb;
		this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
		this.setTitleComponent(Results.getTitle("Errore"));
		this.exit = new Command("Esci");
		this.aboutCommand = About.getAboutCommand();
		this.addCommandListener(this);
		this.addCommand(this.exit);
		this.addCommand(this.aboutCommand);
		this.error = this.getError("");
		this.addComponent(this.error);
	}
	
	private TextArea getError(String message){
		TextArea ret = new TextArea();
		ret.setEditable(false);
		ret.setText(message);
		return ret;
	}
	
	public void setError(String message){
		this.error.setText(message);
	}
	
	public void actionPerformed(ActionEvent ev) {
		Command c = ev.getCommand();
		if(c==this.exit){
			this.hb.quit();
		} else if(c==this.aboutCommand){
			this.hb.about(this);
		}	
	}
}
